<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<title>Events</title>

		<script type="text/javascript" language="javascript" src="../../lib/eventbus.min.js"></script>
		<script type="text/javascript" language="javascript">

			window.onload = function() {

				// ******************************************************************************************
				function myFunction(event) {
					console.log("myFunction type=" + event.type);
				}
				EventBus.addEventListener("my_function_event", myFunction);
				EventBus.dispatch("my_function_event");

				// ******************************************************************************************
				console.log("\n");
				var TestClass1 = function() {
					this.className = "TestClass1";
					this.callback = function(event) {
						console.log(this.className + " = type:" + event.type + " / dispatcher:" + event.target.className);
					}
				};
				var TestClass2 = function() {
					this.className = "TestClass2";
					this.dispatchOurEvent = function() {
						EventBus.dispatch("callback_event", this);
					}
				};
				var t1 = new TestClass1();
				var t2 = new TestClass2();
				EventBus.addEventListener("callback_event", t1.callback, t1);
				t2.dispatchOurEvent();

				// ******************************************************************************************
				console.log("\n");
				var TestClass1 = function() {
					this.className = "TestClass1";
					this.doSomething = function(event, param1, param2) {
						console.log(this.className + ".doSomething");
						console.log("type=" + event.type);
						console.log("params=" + param1 + param2);
						console.log("coming from=" + event.target.className);
					}
				};
				var TestClass2 = function() {
					this.className = "TestClass2";
					this.ready = function() {
						EventBus.dispatch("custom_event", this, "javascript events", " are really useful");
					}
				};

				var t1 = new TestClass1();
				var t2 = new TestClass2();
				EventBus.redirect("custom_event","ready");
				EventBus.on("ready", t1.doSomething, t1);
				t2.ready();

				// ******************************************************************************************
				console.log("\n");
				var winterHandler = function() {
					console.log("arguments", arguments);
				}
				EventBus.on("let-it-snow", winterHandler, null, "and happy", "new year");
				EventBus.emit("let-it-snow", null, "merry", "christmas");
				EventBus.trigger("let-it-snow", null, "merry", "christmas");
				EventBus.dispatch("let-it-snow", null, "merry", "christmas");

			}

		</script>

	</head>
	<body>
		<div id="console.log">

		</div>
	</body>
</html>